package com.lenovo.newsapp.wl;

import android.util.Log;

import com.lenovo.newsapp.activity.MainActivity;
import com.worklight.wlclient.api.WLClient;
import com.worklight.wlclient.api.WLFailResponse;
import com.worklight.wlclient.api.WLProcedureInvocationData;
import com.worklight.wlclient.api.WLRequestOptions;
import com.worklight.wlclient.api.WLResponse;
import com.worklight.wlclient.api.WLResponseListener;

public class WLLoadData {

	private static final String TAG = WLLoadData.class.getSimpleName();
	
	static String responseT = "";
	
	public static String loadData(WLClient client,String adapterName,String procedureName,String page,String pageNum) {

//		String adapterName = "NewsAppAdapter";
//		String procedureName = "getNewsList";
		

		WLProcedureInvocationData invocationData = new WLProcedureInvocationData(
				adapterName, procedureName);

		Object[] parameters = new Object[] { page, pageNum };
		invocationData.setParameters(parameters);

		WLRequestOptions options = new WLRequestOptions();
		options.setTimeout(15000);

		client = WLClient.getInstance();
		client.invokeProcedure(invocationData, new WLResponseListener() {

			public void onSuccess(WLResponse response) {
				String responseText = response.getResponseText();
				responseT = responseText;
				Log.v(TAG, "onSuccess-" + responseText);
			}

			public void onFailure(WLFailResponse response) {
				String responseText = response.getResponseText();
				responseT = responseText;
				Log.v(TAG, "onFailure-" + responseText);
			}

		}, options);
		return responseT;
		

//		Log.v(TAG, "loadData-");
		
		
		
		
//		MainActivity.client = WLClient.getInstance();
////		client.invokeProcedure(invocationData, new MyInvokeListener(), options);
//		MainActivity.client.invokeProcedure(invocationData, new WLResponseListener(){
//
//			public void onSuccess(WLResponse response) {
//				Log.v(TAG, "onSuccess-responseText=");
//					String responseText = response.getResponseText();
//					Log.v(TAG, "onSuccess-responseText="+responseText);
////				MainActivity.updateTextView("Adapter Procedure Invoked Successfuly\n"+ responseText);
//			}
//			public void onFailure(WLFailResponse response) {
//				Log.v(TAG, "onFailure-responseText=");
//				String responseText = response.getResponseText();
//				Log.v(TAG, "onFailure-responseText="+responseText);
////				MainActivity.updateTextView("Failed to Invoke Adapter Procedure\n"+ responseText);
//			}
//
//		}, options);
	
	}

}
